package com.doit.day02

import scala.io.Source

object _05_test {
  def main(args: Array[String]): Unit = {
    val lines: List[String] = Source.fromFile("data/input/word.txt").getLines().toList

    val words: List[String] = lines.flatMap((line:String) => {
      line.split(",")
    })

    //函数的至简原则
    val words1: List[String] = lines.flatMap(line => {
      line.split(",")
    })

    val words2: List[String] = lines.flatMap(_.split(",") )

    val words3: List[String] = lines.flatMap(_.split(",") )

    val grouped1: Map[String, List[String]] = words.groupBy( word => word)

    val grouped: Map[String, List[String]] = words.groupBy(word => word)

    val counted: Map[String, Int] = grouped.map(kv => {
      val key: String = kv._1
      val value: List[String] = kv._2
      val size: Int = value.size
      (key, size)
    })
    println(counted)
  }

}
